<?php
$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();
$objPatient 	= new Patients();
$arrobjPatients = $objPatient->fetchAllPatients();
$arrobjPatients = rekeyObjects( 'Id', $arrobjPatients );

?>
<html>
<head>
<link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script>
	$(document).ready(function() {
		$('#dataTables-example').dataTable();
	});
</script>
<style>
	.thclass{
	font-size:12px;
	}
	.tbclass{
	font-size:12px;
	}
</style>
</head>
<body>
<br>
<?php
$objCasePapers = new CasePapers();

$strSQL = 'SELECT p. * , c. * FROM patients p RIGHT JOIN case_papers c ON p.id = c.patient_id';

	$conditions = array();

	if( true == isset( $_POST['from'] ) ) {
		$conditions[] = "c.updated_on BETWEEN '".mysql_real_escape_string($_POST['from'])."' AND '".mysql_real_escape_string($_POST['to'])."'";
	}
	if( $_POST['p_type_id'] != '' ) {
		$conditions[] = "p.patient_type_id = ".$_POST['p_type_id'];
	}
	if( $_POST['p_area_id'] !='' ) {
		$conditions[] = "p.patient_area_id = ".$_POST['p_area_id'];
	}
	if( count( $conditions ) ) {
		$strSQL.= ' WHERE ' . implode( ' AND ', $conditions );
	}

	$arrobjCasePaper = $objCasePapers->fetchSql( $strSQL );
?>	
<div class="col-lg-10">
	<div class="panel panel-primary">
		
		<div class="panel-heading">
			<div style="float: left;">
				<i class="fa fa-bell fa-fw"></i>Daily Collection Report
			</div>
			<div style="float: right;">
				<input style="color: black;" type="button" name="download" value="Download" onClick="javascript: window.location='modules.php?file=download_daily_report&type=download'" />
			</div>
			<div style="clear: both;"></div>
		</div>
				
		<div class="panel-body">
			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover" id="dataTables-example">
					<thead class="thclass">
						<tr>
							<th>Sr.No</th>
							<th>Case paper ID</th>
							<th>Patient ID</th>
							<th>Patient Name</th>
							<th>Amount Paid</th>
						</tr>	
					</thead>
					<tbody class="tbclass">
                    <?php
                    $i=0; 
					$tot=0;
						if( true == valArr( $arrobjCasePaper ) ) {
							foreach( $arrobjCasePaper as $objCasePaper ) {
							$objPatient = getArrayElementByKey( $objCasePaper->getPatientId(), $arrobjPatients );
							$i++;
							?>
							<tr class="odd gradeX">
						    <td><? echo $i; ?></td>
						    <td><? echo $objCasePaper->getId(); ?></td>
						    <td><? echo $objCasePaper->getPatientId(); ?></td>
							
							<td><? echo ( true == valObj( $objPatient, 'BasePatients' ) ) ? $objPatient->getFirstName() . ' ' . $objPatient->getMiddleName() . ' ' .$objPatient->getLastName() : $objCasePaper->getPatientId(); ?></td>
							
							<td><? echo $objCasePaper->getAmountPaid(); ?></td>
							</tr>
							<?
							$tot = $tot + $objCasePaper->getAmountPaid();
							}
						}
					?> 
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div class="alert alert-danger">Tatal Collection Amount is = <font style="font-size:18px;color:#000000;font-weight:bold;"><?php echo $tot;?> RS</font></div>
</div>
</body>
</html>